package com.tuanzi.loan.web.bean.settlementsystem;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.entity.settlementsystem.SettlementCompany;
import com.tuanzi.loan.business.service.settlementsystem.SettlementCompanyService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.settlementsystem.SettlementCompanyAmountRequest;
import com.tuanzi.loan.vo.response.settlementsystem.SettlementCompanyResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.settlementsystem.SettlementCompanyAmountLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.util.List;

import static com.tuanzi.loan.business.constants.DictionaryCode.SETTLEMENT_BILL_TYPE;

/**
 * @author caiwanlin
 * @create 2018-08-16 20:30
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class SettlementCompanyAmountListBean extends JSFListingBean<SettlementCompanyAmountRequest,SettlementCompanyResponse> {
    @Autowired
    private SettlementCompanyService settlementCompanyService;

    private List<SettlementCompany> companyList;

    @PostConstruct
    public void init() throws Exception {
        companyList = settlementCompanyService.getCompanyList();
        initLazyDataModel();
    }

    private void initLazyDataModel() throws Exception {
        $ = new SettlementCompanyAmountRequest();
        lazyDataModel = new SettlementCompanyAmountLazyDataModel($);
    }

    public void onReset() throws Exception{
        initLazyDataModel();
    }

    @Override
    protected List<String> getDictionaryCodes() {
        return  Lists.newArrayList(SETTLEMENT_BILL_TYPE);
    }
}
